package com.kefu.call.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.call.model.ActivityUserInfo;
import com.kefu.call.service.ActivityUserInfoService;
import com.kefu.call.vo.ActivityUserInfoInsertVo;
import com.kefu.call.vo.ActivityUserInfoSearchVo;
import com.kefu.call.vo.ActivityUserInfoUpdateVo;
import com.kefu.common.annotation.Permission;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

@Api(tags = "活动用户")
@RestController
@RequestMapping("call/activity/user")
public class ActivityUserInfoController extends AbstractBaseController {
    @Resource
    private ActivityUserInfoService activityUserInfoService;

    @PostMapping("/add")
    @ApiOperation(value = "新增活动用户", notes = "新增活动用户,先删除后新增,不做排重处理,需要前端做排重")
    public Result<?> add(@Validated @RequestBody ActivityUserInfoInsertVo activityUserInfoVo) {
    	logger.info("新增活动用户:{}", activityUserInfoVo);
    	
    	List<ActivityUserInfo> list = activityUserInfoVo.convert();
        return ResultGenerator.genSuccessResult(activityUserInfoService.saveUserList(list));
    }

    @Deprecated
    @PostMapping("/delete")
    @ApiOperation(value = "删除活动用户", notes = "删除活动用户")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除活动用户:{}", delete);
    	
        activityUserInfoService.deleteById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }

    @Deprecated
    @PostMapping("/update")
    @ApiOperation(value = "修改活动用户", notes = "修改活动用户",hidden=true)
    public Result<String> update(@Validated @RequestBody ActivityUserInfoUpdateVo activityUserInfoVo) {
    	logger.info("修改活动用户:{}", activityUserInfoVo);
    	
    	ActivityUserInfo info = activityUserInfoVo.convert();
        activityUserInfoService.update(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    @ApiOperation(value = "活动用户详情", notes = "活动用户详情",hidden=true)
    public Result<ActivityUserInfo> detail(@Validated @RequestBody DetailVo detail) {
        logger.info("活动用户查看详情:{}", detail);
        
        ActivityUserInfo activityUserInfo = activityUserInfoService.findById(detail.getId());
        return ResultGenerator.genSuccessResult(activityUserInfo);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询活动得用户列表", notes = "查询活动用户")
    public Result<Page<ActivityUserInfo>> list(@Validated @RequestBody ActivityUserInfoSearchVo search) {    
        logger.info("查询活动用户:{}", search);
        
        Page<ActivityUserInfo> list = activityUserInfoService.search(search);
        return ResultGenerator.genSuccessResult(list);
    }
}
